package cn.chencaiju.App;

import java.awt.Dimension;
import java.awt.Toolkit;

// 子弹类
class Shot implements Runnable {
    int x;
    int y;
    int Direct;
    int speed = 5;//子弹的速度
    boolean isLive = true;

    public Shot(int x, int y, int Direct) {
        this.x = x;
        this.y = y;
        this.Direct = Direct;
    }
    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(50);
            } catch (Exception e) {
            }
            switch (Direct) {
            case 0:
                y -= speed;
                break;
            case 1:
                y += speed;
                break;
            case 2:
                x -= speed;
                break;
            case 3:
                x += speed;
                break;
            default:
                break;
            }

            // 子弹何时死亡

            if (x < 0 || x > MyPanel.backgroundwidth || y < 0 || y > MyPanel.backgroundheight) {
                this.isLive = false;
                break;
            }
        }
    }
}